<template>
  <div>
    <input
      type="text"
      placeholder="输入商品名"
      v-model="title"
    >
    <input
      type="text"
      placeholder="输入价格"
      v-model="price"
    >
    <input
      type="text"
      placeholder="输入浏览量"
      v-model="show_num"
    >
    <input
      type="text"
      placeholder="输入描述"
      v-model="desc"
    >
    <button @click="add_goods">创建商品</button>
  </div>
</template>

<script>

export default {
  data() {
    return {
      // title = models.CharField('商品名', max_length=64)
      // price = models.DecimalField('价格', max_digits=9, decimal_places=2)
      // show_num = models.IntegerField('浏览量', default=0)
      // desc = models.TextField('商品描述', default='商品描述')
      title: '',
      price: '',
      show_num: 0,
      desc: ''
    }
  },
  methods: {
    add_goods() {
      var params = {
        title: this.title,
        price: this.price,
        show_num: this.show_num,
        desc: this.desc
      }
      this.axios.post('http://127.0.0.1:8000/goods/', params).then(res => {
        console.log(res)
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style>
</style>